/*
 *  AppCompositor.cpp
 *  openFrameworks
 *
 *  Created by fregment on 08.06.09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "AppCompositor.h"
#include "VanishingPointOracle.h"

#include "ofAppCocoaWindow.h"


#include <ostream>
#include <istream>

#include <ios>
#include <iostream>

#include <istream>
#include <iostream>
#include <fstream>
#include <iterator>


bool compareSegmentSize(ImageSegment the1, ImageSegment the2){
	
	return (the1.width * the1.height > the2.width * the2.height);
}




//--------------------------------------------------------------
void AppCompositor::setup(){
	
	
	
	ofSetDataPathRoot("data/"); // Somewhow running this as an ordinary Cocoa App changes the path settings....
	
	
	//_myScale = ( 25000.0 / 120.0 )* 0.5 ; //FIXME: get actual window width on resize
	
	//_myScreenHeight=ofGetHeight();
	
	
	
	_myPreviewDirectory = ofToDataPath("Preview");
	
	//_myPreviewDirectory = "/Volumes/Vektor/Segments/Previews Run3";
	
	_mySegmentDirectory = "/Volumes/Vektor/Segments/Segments3";
	_myCompositionDirectory = "/Volumes/Vektor/COMPS/COMP_16" ;
	
	
	_myDatabaser.openDB();
	
	_myRecordMode = false;
	
	
	ofEnableSmoothing();
	ofSetCircleResolution(50);
	_myOverPoint = -1;
	_myPreviewMode=false;
	_showGrid=true;
	
	_gridSize=20;
	_gridDistance=30;
	
	_myPreviewSegmentScaleFactor = 20;
	
	_myFirstRun = true;
	_useKeywords = false;
	_myPointMode = RANDOM;
	_myVKeyPressed=false;
	_mySKeyPressed=false;
	_myTolerance = 5.0;
	
	_myFullscreenMode = false;
	
	_myRecordMode = false;
	_myMousePlayback = false;
	
	_myBorderPercentageMax=1.0;
	_myBorderPercentageMin=0;
	
	_mySaveImageCounter = 0;
	
	
	_myRecycleSegment = false;
	_myIgnorePoints = false;
	
	ofBackground(255,255,255);
	
	
	
	
	
	//_myXMPmediator.fillDatabaseTags();   
	
	_InterfaceKeywords= _myDatabaser.retrieveKeywordsForInterface();   // updates the sourceTags of the Interface with available Tags from the Database.
	
	
	
}








void AppCompositor::setKeywords(std::vector<std::string>* theKeywords){
	
	if(theKeywords != NULL){
		_myKeywords.clear();
	}
	
	_myKeywords = *theKeywords;
	
	printf("APPcount:%i\n",_myKeywords.size());
	
	for(int i=0; i<_myKeywords.size();i++){
		
		printf("KeywordsFromInterface:%s\n",_myKeywords.at(i).c_str());
		
	}
	
	
}


void AppCompositor::interfaceEvent(int theEvent,int theValue){
	
	if(theEvent == CLEAR_GRID){
		
		for (int i=0; i<_myComposerVPs.size(); i++) {
			_myComposerVPs.at(i).deleteGrid();
		}
		
	}
	
	if(theEvent == CLEAR_VP){
		
		_myComposerVPs.clear();
		
		
	}
	
	if(theEvent == CREATE){
		
		printf("DO_CREATE!\n");
		doCreate();
		
		
	}
	
	if(theEvent == SAVE_XML){
		
		saveXML();
	}
	
	
	if(theEvent == SLIDER_BORDER_MIN){
		
		_myBorderPercentageMin=pow(theValue*0.01, 5);
		printf("MAXVALUE:%f---\n",_myBorderPercentageMin);
		
		
	}
	
	if(theEvent == SLIDER_BORDER_MAX){
		
		_myBorderPercentageMax=pow(theValue*0.01, 5);
		printf("MAXVALUE:%f---\n",_myBorderPercentageMax);
		
		
	}
	
	
	if(theEvent == SLIDER_DIST){
		
		
		_gridDistance=theValue;
		
		
		if(_myPointMode==RANDOM){
			for (int i=0; i<_myComposerVPs.size(); i++) {
				
				_myComposerVPs.at(i).deleteGrid();
				_myComposerVPs.at(i).makeGrid(_gridSize,_gridDistance);
				
			}	
			
		}
	}
	
	if(theEvent == SLIDER_SIZE){
		
		_gridSize=theValue;
		
		if(_myPointMode==RANDOM){
			for (int i=0; i<_myComposerVPs.size(); i++) {
				_myComposerVPs.at(i).deleteGrid();
				_myComposerVPs.at(i).makeGrid(_gridSize,_gridDistance);
				
				
			}	
			
		}
	}
	
	
	if(theEvent == SLIDER_TOLERANCE){
		
		_myTolerance=(float)theValue;
		
		
		
	}
	
	
	
	if(theEvent == BACKGROUND){
		
		ofBackground(theValue,theValue,theValue);
		
	}
	
	if(theEvent == KEYWORD_TOGGLE){
		
		_useKeywords = !_useKeywords;
		printf("_useKeywords=%i\n",_useKeywords);
		printf("_myPointMode=%i\n",_myPointMode);
		
		
	}
	
	if(theEvent == PREVIEW_TOGGLE){
		
		_myPreviewMode= !_myPreviewMode;
		
		
	}
	
	
	if(theEvent == POINT_MODE){
		
		_myPointMode =theValue;
		
		
	}
	
	
	if(theEvent == UPDATE_PREVIEW){
		
		if(_myPreviewMode == true){
			updatePreview();
		}
		
		
	}
	
	
	if(theEvent == RECYCLE_SEGMENT_TOGGLE){
		_myRecycleSegment = !_myRecycleSegment;
	}
	
	
	if(theEvent == IGNORE_POINTS_TOGGLE){
		_myIgnorePoints = !_myIgnorePoints;
	}
	
	
}

void AppCompositor::loadXML(){
	
	_myPreviewSegments.clear();
	
	
	_myXMLSettings.loadFile("XML/settings.xml");
	
	int numDragTags = _myXMLSettings.getNumTags("PICTURE:SEGMENT");
	
	if(numDragTags > 0){
		_myXMLSettings.pushTag("PICTURE", numDragTags-1);
		
		int numSegmentTags = _myXMLSettings.getNumTags("SEGMENT");
		
		if(numSegmentTags > 0){
			
			//int totalToRead = MIN(numSegmentTags, NUM_PTS);
			
			for(int i = 0; i < numSegmentTags; i++){
				//the last argument of getValue can be used to specify
				//which tag out of multiple tags you are refering to.
				std::string segmentName = _myXMLSettings.getValue("SEGMENT:NAME", "noname", i);
				float x = _myXMLSettings.getValue("SEGMENT:X", 0.0, i);
				float y = _myXMLSettings.getValue("SEGMENT:Y", 0.0, i);
				int segmentWidth = _myXMLSettings.getValue("SEGMENT:WIDTH", -1, i);
				int segmentHeight = _myXMLSettings.getValue("SEGMENT:HEIGHT", -1, i);
				float vpX = _myXMLSettings.getValue("SEGMENT:VANISHINGPOINT_X", 0.0, i);
				float vpY = _myXMLSettings.getValue("SEGMENT:VANISHINGPOINT_Y", 0.0, i);
				
				ImageSegment segment(segmentName,x,y,segmentWidth,segmentHeight);
				segment.vanishingPoint.x=vpX;
				segment.vanishingPoint.y=vpY;
				
				
				printf("segmentX:%f\n",segment.x);
				
				_myPreviewSegments.push_back(segment);
				
				
			}
		}
		
		//this pops us out of the STROKE tag
		//sets the root back to the xml document
		_myXMLSettings.popTag();
		
		
		
		
		
		
		
		
		
	}
	
	
	
	
	
}




void AppCompositor::saveXML(){
	
	if(_myPreviewSegments.size() > 0){
		
		int lastTagNumber	= _myXMLSettings.addTag("PICTURE");
		//std::string xmlStructure	= "<STROKE>\n";
		
		for(int i=0; i < _myPreviewSegments.size(); i++){
			
			
			_myXMLSettings.pushTag("PICTURE", lastTagNumber);
			int tagNum = _myXMLSettings.addTag("SEGMENT");
			_myXMLSettings.setValue("SEGMENT:NAME", _myPreviewSegments.at(i).filename, tagNum);
			_myXMLSettings.setValue("SEGMENT:X", _myPreviewSegments.at(i).x, tagNum);
			_myXMLSettings.setValue("SEGMENT:Y", _myPreviewSegments.at(i).y, tagNum);
			_myXMLSettings.setValue("SEGMENT:WIDTH", _myPreviewSegments.at(i).width, tagNum);
			_myXMLSettings.setValue("SEGMENT:HEIGHT", _myPreviewSegments.at(i).height, tagNum);
			_myXMLSettings.setValue("SEGMENT:VANISHINGPOINT_X", _myPreviewSegments.at(i).vanishingPoint.x, tagNum);
			_myXMLSettings.setValue("SEGMENT:VANISHINGPOINT_Y", _myPreviewSegments.at(i).vanishingPoint.y, tagNum);
			
			_myXMLSettings.popTag();
			
			
			
			
			
		}
		
		
		char filenameXML[100];
		char filenameImage[100];
		
		time_t Zeitstempel;
		tm *nun;
		Zeitstempel = time(0);
		nun = localtime(&Zeitstempel);
		
		stringstream zeit_buendel;
		zeit_buendel << nun->tm_mday << '_' << nun->tm_mon+1 << '_'
		<< nun->tm_year+1900 << "_" << nun->tm_hour
		<< '_' << nun->tm_min << endl;
		
		
		sprintf(filenameXML,"XML/settings_%s.xml",zeit_buendel.str().c_str());	
		sprintf(filenameImage,"XML/settings_%s.png",zeit_buendel.str().c_str());	
		
		
		_myXMLSettings.saveFile(filenameXML);	
		
		ofImage myImage;
		myImage.grabScreen(0,0,ofGetWidth(),ofGetHeight());
		myImage.saveImage(filenameImage);
		
		
	}
	
	
	
	
	
	
}








//--------------------------------------------------------------
void AppCompositor::update(){
	
	
}





//--------------------------------------------------------------
void AppCompositor::draw(){
	
	
	if(_myMousePressed & _myRecordMode){
		_myMouseRecorder.addPosition(_myMouseX,_myMouseY);
		
	}
	
	if(_myMousePlayback && _myMouseRecorder.isAtEnd() == false){
		
		ofSetColor(255, 0, 0);
		ofFill();
		ofCircle(10,10, 10);
		
		Point2f position = _myMouseRecorder.get();
		
		if(_myComposerVPs.size() > 0){
			
			
			_myComposerVPs.at(0).shiftPoints(position.x, position.y);
			_myComposerVPs.at(0).x = position.x;
			_myComposerVPs.at(0).y = position.y;
			
			
			if(_myPreviewMode ==true){
				updatePreview();
			}
			
			
		}
		
		
		_myMouseRecorder.advance();
		
		
		
	}
	if(_myMouseRecorder.isAtEnd()){
		_myMousePlayback=false;
		_myMouseRecorder.reset();
		
	}
	
	
	
	
	if(_myFirstRun == true){
		
		_myScale= ( 25000.0 / (float)ofGetWidth()) * 1.5; //FIXME: get actual window width on resize
		_myScale = _myPreviewSegmentScaleFactor;
		
		printf("the scale is:%f\n",_myScale);
		_myFirstRun = false;
	}
	
	
	
	if(_myPreviewMode == true){
		
		drawPreview();
		
		ofSetColor(0xFFFFFF);
		ofEnableAlphaBlending();
		
	}
	
	
	
	if(_showGrid == true){
		
		
		for (int i=0; i<_myComposerVPs.size(); i++) {
			
			
			
			if(_myComposerVPs.at(i).overState ==true){
				ofNoFill();
				ofSetColor(128);
				ofSetLineWidth(0.6);
				ofCircle(_myComposerVPs.at(i).x, _myComposerVPs.at(i).y, _myComposerVPs.at(i).r);
			}
			
			ofFill();
			
			if(_myComposerVPs.at(i).isActive ==true){
				
				ofSetColor(0,255,0);
			}
			else{
				ofSetColor(100,0,0);
			}
			
			
			ofCircle(_myComposerVPs.at(i).x, _myComposerVPs.at(i).y, _myComposerVPs.at(i).r-7);
			
			
			_myComposerVPs.at(i).drawGrid();
		}
		
		
	}
	
	
	if(_myPointMode==ERASE){
		
		ofHideCursor();
		
		ofNoFill();
		
		
		ofSetColor(128,128,128,100);
		
		ofCircle(_myMouseX,_myMouseY, 10);
		
	}else{
		
		ofShowCursor();
		
	}
	
	
	
	if(_myMousePlayback && _myMouseRecorder.isAtEnd() == false && _myPreviewMode ==true){
		
		saveFrame();
	}
	
	
	
}






//--------------------------------------------------------------
void AppCompositor::keyPressed  (int key){
	
	
	if(key==127 && _myMousePressed == true){
		int vecPos = -1;
		for (int i=0; i<_myComposerVPs.size(); i++) {
			if(_myComposerVPs.at(i).overState ==true){
				
				vecPos = i;
				
			}
			if(vecPos != -1){
				
				_myComposerVPs.erase(_myComposerVPs.begin()+vecPos);
			}
		}
		
		
	}
	
	
	
	
	if(key == 'g'){
		
		_showGrid= !_showGrid;
	}
	
	if(key == 's'){
		
		_mySKeyPressed=true;
	}
	
	if(key == 'a'){
		
		_myMouseRecorder.clear();
		_myRecordMode = true;
		
	}
	
	if(key == ' '){
		_myRecordMode = false;
		_myMousePlayback = true;
		
		
		
	}
	
	
	
	if(key == 't'){
		
		saveXML();
	}
		
	if(key == 'l'){
		loadXML();
	}
	
	
	
	
	if(key == 'v'){
		
		_myVKeyPressed=true;
	}
	
	if(key == 'f'){
		_myFullscreenMode = !_myFullscreenMode;
		
		ofSetFullscreen(_myFullscreenMode);
	}
	
}




void AppCompositor::saveFrame(){
	
	_mySaveImageCounter++;
	
	ofImage myImage;
	char filename [200];
	
	
	sprintf(filename,"%sframe_%i.png",ofToDataPath("animation/").c_str(),_mySaveImageCounter);	
	
	myImage.grabScreen(0,0,ofGetWidth(),ofGetHeight());
	myImage.saveImage(filename);
	
	
}




void AppCompositor::drawPreview(){
	
	
	
	for(int i = 0; i < _myPreviewSegments.size(); i++){
		
		
		std::string myPreviewSegmentPath = _myPreviewDirectory + "/" + _myPreviewSegments.at(i).filename; 
		ofImage myPreviewImage;
		
		ofSetColor(0xFFFFFF);
		
		ofEnableAlphaBlending();
		myPreviewImage.loadImage(myPreviewSegmentPath);
		
		
		ImageSegment myPreviewSegment = _myPreviewSegments.at(i);
		
		Point2f mySegmentCenter(myPreviewSegment.x, myPreviewSegment.y); 
		//mySegmentCenter.add(myPreviewSegment.vanishingPoint.x, myPreviewSegment.vanishingPoint.y);
		
		mySegmentCenter.subtract((myPreviewSegment.width * 0.5) , (myPreviewSegment.height * 0.5)  );
		
		mySegmentCenter.divide(_myScale);
		
		
		mySegmentCenter.add(myPreviewSegment.vanishingPoint.x / _myScale, myPreviewSegment.vanishingPoint.y / _myScale);
		
		
		float myImageScale = (1/_myScale) ;
		float myWidth = myPreviewSegment.width * myImageScale;
		float myHeight = myPreviewSegment.height * myImageScale;
		
		
		
		if(myPreviewImage.width > 0){ // only draw if picture is existent
			myPreviewImage.draw(mySegmentCenter.x, mySegmentCenter.y, myWidth, myHeight );
		}
		
		//std::cout << (float)(_myPreviewSegments.at(i).width/100) << "\n";
	}
	
}




void AppCompositor::updatePreview(){	
	
	
	_myPreviewSegments.clear();
	_myUsedSegments.clear();
	
	int myCount = 0;
	
	for(int i = 0; i <_myComposerVPs.size(); i++){
		ComposerVP myVP = _myComposerVPs.at(i); // copy vanising point
		
		/* Scale up */
		myVP.x *= _myScale;
		myVP.y *= _myScale;
		
		
		if(_myRecycleSegment) _myUsedSegments.clear();
		
		
		
		if(!_myIgnorePoints){
			for(int j = 0; j < myVP.gridPoints.size(); j++){
				
				
				
				Point2f myPoint = myVP.gridPoints.at(j);
				Point2f myScaledPoint= myVP.gridPoints.at(j);
				
				myScaledPoint.scale(_myScale);
				
				
				printf("The scale is %f", _myScale);
				printf("X of the point is %f",myScaledPoint.x);
				
				std::vector<ImageSegment>* mySegments;
				
				if(_useKeywords == true){
					
											
					printf("-------------------AppCompositor:: _useKeywords==true _myIgnorePoints=false-----------------\n");
					mySegments = _myDatabaser.retrieveGoodSegements(myScaledPoint.x , myScaledPoint.y  , _myTolerance * _myScale  , 1500 * 1000, 60000000,_myBorderPercentageMin,_myBorderPercentageMax, &_myUsedSegments, &_myKeywords);
						
					
					
				}else{
					printf("----------------AppCompositor:: _useKeywords==false---------------\n");
					//mySegments = _myDatabaser.retrieveGoodSegements(myScaledPoint.x  , myScaledPoint.y , _myTolerance * _myScale  , 1500 * 1000, 60000000, &_myUsedSegments, NULL);
					mySegments = _myDatabaser.retrieveGoodSegements(myScaledPoint.x  , myScaledPoint.y , _myTolerance * _myScale  , 0, 600000000,_myBorderPercentageMin,_myBorderPercentageMax, &_myUsedSegments, NULL);
					
				}
				
				
				
				/* Take one random */
				if(mySegments && mySegments->size() > 0 && !_myIgnorePoints){
					
					
					ImageSegment mySegment = mySegments->at( VanishingPointOracle::randomInt(mySegments->size()) );
					
					_myUsedSegments.push_back(mySegment.databaseID);
					
					
					/* Set Vanishing point coordinates  */
					mySegment.vanishingPoint.x = myVP.x;
					mySegment.vanishingPoint.y = myVP.y;
					
					
					_myPreviewSegments.push_back(mySegment);
					
					
				}
				
				
				
				
				
				
				
				delete mySegments;
				
			}
			
			
		} else {
			
			std::vector<ImageSegment>* mySegments;

			
			
			if(_useKeywords){
				
				printf("-------------------AppCompositor:: _useKeywords==true _myIgnorePoints=true-----------------\n");
				mySegments = _myDatabaser.retrieveAllSegments(_myBorderPercentageMin, _myBorderPercentageMax, &_myKeywords);
			}
				
			
			/* Take all */
			if(mySegments && mySegments->size() > 0 && _myIgnorePoints){
				
				for(int i=0; i < mySegments->size(); i++){
					
					ImageSegment mySegment = mySegments->at(i);
					
					_myUsedSegments.push_back(mySegment.databaseID);
					
					
					/* Set Vanishing point coordinates  */
					mySegment.vanishingPoint.x = myVP.x;
					mySegment.vanishingPoint.y = myVP.y;
					
					
					_myPreviewSegments.push_back(mySegment);
					
				}
				
				
			}
			
			
			delete mySegments;

			
		}
		
		
		
	}
	
	std::sort(_myPreviewSegments.begin(), _myPreviewSegments.end(), compareSegmentSize);
	
	
	
	
	
	
}










void AppCompositor::doCreate(){
	
	
	
	int myCount = 0;
	
	for(int i = 0; i <_myPreviewSegments.size(); i++){
		
		ImageSegment mySegment = _myPreviewSegments.at(i);
		
		Point2f myPoint(mySegment.x,mySegment.y);
		myPoint.add(mySegment.vanishingPoint.x,mySegment.vanishingPoint.y);
		myPoint.subtract(mySegment.width*0.5, mySegment.height*0.5);
		
		
		int myX = round(myPoint.x);
		int myY = round(myPoint.y);
		
		
		ostringstream myFileName;
		myFileName << setw(4) << setfill('0') <<  myCount++ << "_x" << myX << "_y" << myY << "_sc1_segment." << mySegment.filename;
		
		std::cout << myFileName.str() << "\n";
		
		
		std::string myIn = _mySegmentDirectory + "/" + mySegment.filename;
		std::string myOut = _myCompositionDirectory + "/" +  myFileName.str();
		
		
		std::ifstream ifs( (char*)myIn.c_str(), std::ios::binary);
		std::ofstream ofs( (char*)myOut.c_str(), std::ios::binary);
		
		
		ofs << ifs.rdbuf();
		
	}
	
	printf("Hoooeray\n");
	
}



//--------------------------------------------------------------
void AppCompositor::keyReleased(int key){
	
	if(key=='v'){
		
		_myVKeyPressed=false;
	}
	if(key=='s'){
		
		_mySKeyPressed=false;
	}
	
}

//--------------------------------------------------------------
void AppCompositor::mouseMoved(int x, int y ){
	
	_myMouseX = x;
	_myMouseY = y;
	
	
	
	
	
	
	
	
	
	
	_myOverPoint=-1;
	for (int i=0; i<_myComposerVPs.size(); i++) {
		
		if(_myComposerVPs.at(i).isOver(x,y) == true){
			
			_myComposerVPs.at(i).overState =true;
			_myOverPoint=i;
			
		}else{
			_myComposerVPs.at(i).overState =false;
			
		}
	}
	
}

//--------------------------------------------------------------
void AppCompositor::mouseDragged(int x, int y, int button){
	
	_myMouseX=x;
	_myMouseY=y;
	
	
	if(_myVKeyPressed==FALSE && _myOverPoint==-1 && _myPointMode == MANUAL ){
		
		
		
		for(int i=0; i<_myComposerVPs.size(); i++){
			
			if(_myComposerVPs.at(i).isActive==true){
				
				_myComposerVPs.at(i).addGridPoint(x,y);
				
				
			}
		}
		
	}
	
	
	
	for (int i=0; i<_myComposerVPs.size(); i++) {
		
		if(_myPointMode == ERASE && _myComposerVPs.at(i).isActive){
			
			std::vector<int> erasedPoints;
			
			for(int j=0; j<_myComposerVPs.at(i).gridPoints.size(); j++){
				
				
				int _VPX =_myComposerVPs.at(i).x;
				int _VPY =_myComposerVPs.at(i).y;
				
				if(_myComposerVPs.at(i).gridPoints.at(j).isOver(x-_VPX,y-_VPY,10) == true){
					
					
					
					
					erasedPoints.push_back(j);
					
					
				}
				
			}
			
			for(int u=0; u<erasedPoints.size(); u++){
				
				_myComposerVPs.at(i).gridPoints.erase(_myComposerVPs.at(i).gridPoints.begin()+erasedPoints.at(u));
			}
			
		}
		
		
		
		
		
		if(_myComposerVPs.at(i).overState ==true){
			
			if(_myPointMode==MANUAL && _mySKeyPressed){
				
				_myComposerVPs.at(i).shiftPoints(x,y);
				
			}
			
			
			_myComposerVPs.at(i).x = x;
			_myComposerVPs.at(i).y = y;
			
			
			
			if(_myPointMode==RANDOM){
				_myComposerVPs.at(i).deleteGrid();
				_myComposerVPs.at(i).makeGrid(_gridSize,_gridDistance);
			}
			
			
		}
		
	}
	
}

//--------------------------------------------------------------
void AppCompositor::mousePressed(int x, int y, int button){
	
	
	_myMousePressed = true;
	
	
	if(_myVKeyPressed==FALSE && _myOverPoint==-1 && _myPointMode == MANUAL ){
		
		for(int i=0; i<_myComposerVPs.size(); i++){
			
			if(_myComposerVPs.at(i).isActive==true){
				
				_myComposerVPs.at(i).addGridPoint(x,y);
				
				
			}
		}
		
	}	
	
	
	
	
	
	if(_myOverPoint==-1 && _myVKeyPressed==TRUE  ){
		
		ComposerVP myVP(x,y,10,_gridSize,_gridDistance);
		_myComposerVPs.push_back(myVP);
		
		if(_myPointMode==RANDOM){
			_myComposerVPs.back().makeGrid(_gridSize,_gridDistance); 
			printf("RANOM MAKE GRID JA");
		}
		
		
		
		for(int i=0; i<_myComposerVPs.size(); i++){
			
			_myComposerVPs.at(i).isActive=false;
		}
		
		_myComposerVPs.at(_myComposerVPs.size()-1).isActive=true;
		
		
		
	}
	if(_myOverPoint !=-1){
		
		for(int i=0; i<_myComposerVPs.size(); i++){
			
			_myComposerVPs.at(i).isActive=false;
		}
		
		
		_myComposerVPs.at(_myOverPoint).isActive=true;
		
		
	}
	
	
	
	
}

//--------------------------------------------------------------
void AppCompositor::mouseReleased(int x, int y, int button){
	_myMousePressed = false;
	
	if(_myRecordMode = true){
		_myRecordMode = false;
		
		
	}
	
	
	if(_myPreviewMode == true){
		updatePreview();
	}
}

//--------------------------------------------------------------
void AppCompositor::windowResized(int w, int h){
	
	printf("windowSize:%i\n",ofGetWidth());
	printf("windowSize:%i\n",ofGetHeight());
	
}













